<?php
namespace Wap\Controller;
use Wap\Controller\CommonController;
class IndexController extends CommonController {

    /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function index() {

 
        //首页lunbo
        $li=M('sylunbo');
        $roll=$li->order('id desc')->limit(5)->select();

 
        $this->assign('roll',$roll);

         //资讯读取

        $z=M('show');
        $zixun=$z->order('id desc')->limit(4)->select();
       // $zixun1=$z->order('id asc')->limit(3)->select();


        $this->assign('zixun',$zixun);
   $this->assign('zixun1',$zixun1);

        //店面展示
        $pic=M('show');
        $id=I('get.id');
        $show=$pic->order('id desc')->limit(6)->select();

            foreach ($show as $key => $value) {

                $show[$key]['intro']=mb_substr(htmlspecialchars_decode($value['intro']),0,30,'utf-8');
                
              # code...
            }

        $this->assign('show',$show);

        //展示
        $ty=M('zlist');
        $type=$ty->order('id asc')->select();
     
        $this->assign('type',$type);

           //  商品展示
           $sp=M('shangpin');
           $shangpin=$sp->order('id desc')->limit(8)->select();
            $this->assign('shangpin',$shangpin);

        //首页预约人数
        $c=M('yuyue');
        $ci = $c->where('to_days(time)=to_days(now())')->count();
       
          $cc=M('tiyan');
       $tiyan=$cc->select();

     $this->assign('tiyan',$tiyan);
        $this->assign('ci',$ci);
        // 圈子
        $quanzi=M('quanzi')->alias('a')->field('a.id,a.title,a.content,a.img,a.uid,b.touxiang,b.user')->join('zyb_user b on b.id=a.uid')->order('id desc')->limit(4)->select();
        foreach ($quanzi as $key => &$value) {
          $img = explode(",",$value['img']);

         $value['img']=$img[0];

        }

    $this->assign('quanzi',$quanzi);
        
        

 //sheji
     $arr['status']=1;
      $arr['zt']=2;
           

  $sheji=M('user')->where($arr)->order('id desc')->limit(10)->select();
  foreach ($sheji as &$value) {
      $ggg=M('shangpin')->where('userid='.$value['id'])->count();
              
        $value['count']=$ggg;
  
  }





         $this->sheji=$sheji;
        $this->display();
    }



    public function yuyue(){
      
      // if(empty($_SESSION['userid'])){
      //   $this->error("预约失败，请登录",U('User/login'));
      // }
      $m=M('yuyue');



      $data['name']=I('post.name');
      $data['address']=I('post.sheng').I('post.shi').I('post.qu');
      $data['tiyan']=I('post.tiyan');
      $data['time']=I('post.time');
      $data['tel']=I('post.tel');
      $data['uid']=$_SESSION['userid'];
       if ($m->add($data)) {
          $this->redirect(U('Index/index'));
       }else{
           $this->error('提交失败',U('Index/index'));

       }


   }



     public function spid(){

      $spid=I('post.spid');
   
      $sp=M('shangpin');
        $ty1=M('zlist');
      $tzlist=$ty1->where('id='.$spid)->find();
      $sps=$sp->where(array('fengge'=>$tzlist['type_name']))->order('id desc')->limit(8)->select();
       echo json_encode($sps);

      





     }

    
  public function search(){

          $list=M('zlist')->select();
          
          $huxing=M('huxing')->order('id asc')->select();
          
          $fengge = I("get.fengge");
       $huxing1 = I("get.huxing");
       $where = "";

       if(!empty($fengge)){
          $data = M('zlist')->where("id = $fengge")->find();
          if(empty($where)){
            $where .= "a.fengge = '".$data['type_name']."'";
          }else{
            $where .= " and a.fengge = '".$data['type_name']."'";
          }
          
           
       }

       if(!empty($huxing1)){
          $data1 = M('huxing')->where("id=$huxing1")->find();
          if(empty($where)){
            $where .= "a.huxing = '".$data1['huxing']."'";
          }else{
            $where .= " and a.huxing = '".$data1['huxing']."'";
          }
       }
       
       $title=I('post.title');
       $map['a.name'] =array('like',"%$title%");
          $map['a.fengge'] =array('like',"%$title%");
          $map['a.huxing'] =array('like',"%$title%");
          $map['_logic'] = 'or';
    $shangpin=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where($map)->order("a.id desc")->select();
         
            $this->assign("fengge",$fengge);
      $this->assign('list',$list);
      $this->assign('huxing',$huxing);
      $this->assign('huxing1',$huxing1);
            $this->assign('shangpin',$shangpin);
            $this->display();
        
    }  


}
 
?>